package com.health.controller;

import com.health.common.constant.MessageConstant;
import com.health.common.entity.CheckGroup;
import com.health.common.entity.CheckItem;
import com.health.common.vo.QueryPageBean;
import com.health.common.vo.RespBean;
import com.health.common.vo.RespPageBean;
import com.health.service.CheckGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkGroup")
public class CheckGroupController {
    @Autowired
    private CheckGroupService checkGroupService;

    @GetMapping("/")
    public List<CheckGroup> getAllCheckGroup(){
        return checkGroupService.getAllCheckGroup();
    }

    @GetMapping("/condition")
    public RespPageBean getAllCheckGroupByCondition(QueryPageBean queryPageBean){
        return checkGroupService.getAllCheckGroupByCondition(queryPageBean);
    }

    @GetMapping("/getAllGroup")
    public List<CheckGroup> getAllCheckGroup4SetMeal(){
        return checkGroupService.getAllCheckGroup4SetMeal();
    }

    @GetMapping("/getGroup4SetMeal")
    public List<CheckGroup> getGroup4SetMeal(Integer id){
        return checkGroupService.getGroup4SetMeal(id);
    }

    @GetMapping("/{id}")
    public List<CheckItem> getCheckItemByGroupId(@PathVariable Integer id){
        return checkGroupService.getCheckItemByGroupId(id);
    }

    @GetMapping("/itemIds/{id}")
    public Integer[] getCheckItemIdsByGroupId(@PathVariable Integer id){
        return checkGroupService.getCheckItemIdsByGroupId(id);
    }

    @PostMapping("/")
    public RespBean addCheckGroup(CheckGroup checkGroup,Integer[] items){
        if(checkGroupService.addCheckGroup(checkGroup,items) == 1){
            return RespBean.ok(MessageConstant.ADD_CHECKGROUP_SUCCESS);
        }
        return RespBean.error(MessageConstant.ADD_CHECKGROUP_FAIL);
    }

    @DeleteMapping("/{id}")
    public RespBean deleteCheckGroupById(@PathVariable Integer id){
        if(checkGroupService.deleteCheckGroupById(id) == 1){
            return RespBean.ok(MessageConstant.DELETE_CHECKGROUP_SUCCESS);
        }
        return RespBean.error(MessageConstant.DELETE_CHECKGROUP_FAIL);
    }

    @PutMapping("/")
    public RespBean updateCheckGroup(CheckGroup checkGroup,Integer[] items){
        if(checkGroupService.updateCheckGroup(checkGroup,items) == 1){
            return RespBean.ok(MessageConstant.EDIT_CHECKGROUP_SUCCESS);
        }
        return RespBean.error(MessageConstant.EDIT_CHECKGROUP_FAIL);
    }

}
